package com.genius.adminmanager.menu.controller;

import java.sql.SQLException;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.genius.adminmanager.menu.entity.MenuJson;
import com.genius.adminmanager.other.entity.ResponseJson;
import com.genius.workflow.util.ConnectionException;
import com.genius.workflow.util.DBClosedException;
import com.genius.workflow.util.TreeUtils;

@Controller
public class MenuDeleteController {
	@PostMapping("/adminmanager/menu/batchdelMenu")
	@ResponseBody
	public JSONObject batchdelMenu(@RequestBody JSONObject json,HttpSession session){
		JSONObject response = new JSONObject();
		try {
			TreeUtils.delByIdTree("t_menu", MenuJson.menuId,MenuJson.parentId, json);
			//如果删除的是menu的话，要把当前的角色及menuId 从t_menu_field和 t_data
			response.put(ResponseJson.status, ResponseJson.status_Success);
			response.put(ResponseJson.msg, "删除菜单成功");
		}  catch (ConnectionException e) {
			response.put(ResponseJson.status, ResponseJson.status_Failed);
    		response.put(ResponseJson.msg, ResponseJson.msg_DB_Connect_Failed);
		} catch (DBClosedException e) {
			response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_DB_Closed_Failed);
		} catch (SQLException e) {
			response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, "删除菜单出错");
		}
		response.put(ResponseJson.code, 0);
		return response;
	}
}
